﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ShopOnline.Views
{
    public partial class QuantityChildWindow : ChildWindow
    {
        public ProductInCart productToAdd
        {
            get;
            private set;
        }

        public QuantityChildWindow(ProductInCart product)
        {
            InitializeComponent();

            this.productToAdd = product;
            this.DataContext = productToAdd;
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                this.productToAdd.Ammount = int.Parse(TextBoxQuantity.Text);
                if (this.productToAdd.Ammount <= 0)
                {
                    ChildWindow err = new ErrorWindow("Enter correct integer quantity!",
                        "Enter possitive quantity.");
                    err.Show();
                    return;
                }
            }
            catch (Exception)
            {
                ChildWindow err = new ErrorWindow("Enter correct integer number.", "");
                err.Show();
                return;
            }
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

